package com.ruoyi.web.controller.admin;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.module.domain.Cpis;
import com.ruoyi.module.service.ICpisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * CPISController
 *
 * @author fubojin
 * @date 2024-12-17
 */
@RestController
@RequestMapping("/admin/cpis")
public class AdminCpisController extends BaseController
{
    @Autowired
    private ICpisService cpisService;

    /**
     * 查询CPIS列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Cpis cpis)
    {
        startPage();
        List<Cpis> list = cpisService.selectCpisList(cpis);
        return getDataTable(list);
    }

    /**
     * 导出CPIS列表
     */
    @Log(title = "CPIS", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cpis cpis)
    {
        List<Cpis> list = cpisService.selectCpisList(cpis);
        ExcelUtil<Cpis> util = new ExcelUtil<Cpis>(Cpis.class);
        util.exportExcel(response, list, "CPIS数据");
    }

    /**
     * 获取CPIS详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cpisService.selectCpisById(id));
    }

    /**
     * 新增CPIS
     */
    @Log(title = "CPIS", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cpis cpis)
    {
        return toAjax(cpisService.insertCpis(cpis));
    }

    /**
     * 修改CPIS
     */
    @Log(title = "CPIS", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cpis cpis)
    {
        return toAjax(cpisService.updateCpis(cpis));
    }

    /**
     * 删除CPIS
     */
    @Log(title = "CPIS", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cpisService.deleteCpisByIds(ids));
    }
}
